home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ETO Development Tools 4
/
ETO Development Tools 4.iso
/
Tools - Objects
/
Virtual User 1.0
/
Example Libraries
/
TimeLib.vu
< prev
next >
Wrap
Text File
|
1991-01-25
|
3KB
|
103 lines
#
# File: TimeLib.vu
#
# Contains: Tasks that make it easier to work with time in VU.
#
# Written by: Sean Flynn
#
# Copyright: © 1990 by Apple Computer, Inc., all rights reserved.
#
# Change History:
#
# 1/17/91 Rick added task TimeElapsed
# 1/25/91 naga modified header and edited formats
#
# To Do:
#
# *****************************************************************************************
task WaitForTime( end_hour := 0, end_minute := 0, end_second := 0 )
# WaitForTime task. Wait until a specified time of day.
begin
while match[time h:?h2 s:?s2] and
( h2 / 100 <> end_hour or
h2 mod 100 < end_minute or
s2 < end_second ) do;
end;
# *****************************************************************************************
task PrintCurrentTime(print_date := true) begin
# This task pretty prints the current time. The format is as follows:
# <hour of day>:<minutes>:<seconds> <AM or PM>
# It also takes one parameter that indicates whether the date should be printed.
# If the actual parameter passed is a true value, the current date is also printed.
# If no parameter is passed, the date is printed by default.
# The format of the date is as follows:
# <month>/<day>/<year>
#
match [time h:?hour s:?secs d:?day m:?month y:?year];
hour_of_day := hour / 100;
if(hour < 1200) begin # in AM
if(hour_of_day) print hour_of_day;
else print '12';
meridian := ' AM';
end;
else begin # in PM
if hour_of_day = 12 print hour_of_day;
else print hour_of_day - 12;
meridian := ' PM';
end;
print ':',(hour mod 100) / 10,(hour mod 10),':',secs;
print meridian;
if(print_date) begin
print " ",month,"/",day,"/",(year mod 100) / 10,(year mod 10);
end;
end;
(* Example Usage:
print_current_time(true);
*)
# *****************************************************************************************
Task TimeElapsed( StartTime, StopTime )
# this task computes the difference between the start & stop time descriptors and
# returns the result in a time desciptor. The dates are ignored.
begin
StartHour := StartTime.h / 100;
StartMinute := StartTime.h mod 100;
StopHour := StopTime.h / 100;
StopMinute := StopTime.h mod 100;
##### Subtract seconds
if( StopTime.s < StartTime.s ) # must borrow from minutes column
begin
if( StopMinute = 0 ) # must borrow from hours column
begin
StopHour := StopHour - 1;
StopMinute := StopMinute + 60;
end;
StopMinute := StopMinute - 1;
StopTime.s := StopTime.s + 60;
end;
StopTime.s := StopTime.s - StartTime.s;
##### Subtract minutes
if( StopMinute < StartMinute ) # must borrow from hours column
begin
StopHour := StopHour - 1;
StopMinute := StopMinute + 60;
end;
StopMinute := StopMinute - StartMinute;
##### Subtract minutes
StopHour := StopHour - StartHour;
return [ time y:0 m:0 d:0 h:(( StopHour * 100 ) + StopMinute) s:(StopTime.s) ];
end;